<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('角色列表')" />
	<style type="text/css">
		label.layui-form-label {width: 100px;padding-right: 0px;}
	</style>
</head>
<body class="no-skin">
 <div class="main-container" id="main-container">
	<div class="main-content">
	    <div class="north">
	        <div class="north-content">
	            <form>
					<th:block th:include="listinclude :: searchTop" />
				</form>
	        </div>
	    </div>
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	</div>
 </div>
 <div id="form_d" style="padding:10px 60px 10px 10px;display:none;">
 <form class="layui-form post_form" lay-filter="fform">
	 <input type="hidden" id="guid1" name="guid">
	 <div class="layui-form-item">
	     <label class="layui-form-label"><font class="f_red">*</font><span>角色名称：</span></label>
	     <div class="layui-input-block">
	         <input type="text" name="roleName" id="roleName1" value="" autocomplete="off" onblur="inputOnBlur(this)" class="layui-input">
	     </div>
	 </div>
	 <div class="layui-form-item">
         <label class="layui-form-label"><span>权限：</span></label>
         <div class="layui-input-block">
             <select name="roleDataLimit" id="roleDataLimit1">
             <option>请选择权限</option>
             <option th:each="dataLimitMap:${dataLimitMap}" th:value="${dataLimitMap.key}" th:valuecn="${dataLimitMap.value}" th:text="${dataLimitMap.value}" ></option>
             </select>
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label"><span>岗位说明：</span></label>
         <div class="layui-input-block">
             <input type="text" name="vGwZz" id="vGwZz1" value="" autocomplete="off" class="layui-input">
         </div>
     </div>
	 <div class="layui-form-item">
         <label class="layui-form-label"><span>首页模板：</span></label>
         <div class="layui-input-block">
             <select name="pageTemplate" id="pageTemplate">
             <option value="">请选择模板</option>
             <option th:each="pageTemplateMap:${pageTemplateMap}" th:value="${pageTemplateMap.value}" th:valuecn="${pageTemplateMap.value}" th:text="${pageTemplateMap.value}" ></option>
             </select>
         </div>
     </div>
     <!-- 
     <div class="layui-form-item">
         <label class="layui-form-label"><span>续签提醒(天)：</span></label>
         <div class="layui-input-block">
             <input type="number" name="remindDaysForContract" id="remindDaysForContract1" min="0" autocomplete="off" class="layui-input">
         </div>
     </div>
      -->
     <div class="layui-form-item">
         <label class="layui-form-label"><span>排序值：</span></label>
         <div class="layui-input-block">
             <input type="number" name="roleOrder" id="roleOrder1" min="0" autocomplete="off" class="layui-input">
         </div>
     </div>
	 <div class="layui-form-item">
         <label class="layui-form-label"><span>状态：</span></label>
         <div class="layui-input-block">
             <input type="checkbox" checked name="deletedtext" id="deletedtext1" lay-filter="fdeleted" lay-skin="switch" lay-text="启用|禁用">
             <input type="hidden" name="deleted" id="deleted1" value="0">
         </div>
     </div>
</form>
</div>
<th:block th:include="include :: footer" />
 <th:block th:include="include :: motif-alone" />
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" shiro:hasPermission="system:user:add">
            <p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增</span></p>
        </div>
    </div>
</script>
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-xs dhicon dh-edit" lay-event="edit" shiro:hasPermission="system:role:edit"><span class="fa_span">编辑</span></a>
    <a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-edit" shiro:lacksPermission="system:role:edit"><span class="fa_span"></span>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" lay-event="del" shiro:hasPermission="system:role:delete"><span class="fa_span">删除</span></a>
    <a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-remove" shiro:lacksPermission="system:role:delete"><span class="fa_span"></span>删除</a>
	<a class="layui-btn layui-bg-orange layui-btn-xs dhicon dh-group" lay-event="dataSet" shiro:hasPermission="system:role:edit"><span class="fa_span">数据权限</span></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-group" shiro:lacksPermission="system:role:edit"><span class="fa_span"></span>数据权限</a>
	<a class="layui-btn layui-bg-cyan layui-btn-xs dhicon dh-cogs" lay-event="funSet" shiro:hasPermission="system:role:edit"><span class="fa_span">功能权限</span></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-cogs" shiro:lacksPermission="system:role:edit"><span class="fa_span"></span>功能权限</a>
	<a class="layui-btn layui-bg-cyan layui-btn-xs dhicon dh-font" lay-event="fieldSet" shiro:hasPermission="system:role:edit"><span class="fa_span">字段权限</span></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-font" shiro:lacksPermission="system:role:edit"><span class="fa_span"></span>字段权限</a>
 </script>
 <script th:inline="javascript">
    /*<![CDATA[*/
    var gridColumns = [[${gridColumns}]];
    var k_fields =[[${fields}]];
	var dataLimit = [[${dataLimitMap}]];
	var pageTemplate = [[${pageTemplateMap}]];
	var moduleTable = [[${moduleTable}]];
    /*]]>*/
</script>
<script type="text/javascript">
var $,layer,form,table,laydate,wherestr={};
 layui.use(['laydate', 'table','form','layer','jquery'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate;
	$.tablelist.init({
		elem: '#dhtable'
		,url: "/system/role/list"
		,initSort: {field: 'roleOrder',type: 'asc'}
		,where: {
	    	field: 'roleOrder' //排序字段
	    	,order: 'asc' //排序方式
	    }
		,sort:true
		,cols: [[
			{type:'numbers',fixed:'left'},
		    {field: 'roleName',title: '角色名称',width:140, sort: true,fixed:'left'},
		    {field: 'roleDataLimit',title: '基础数据权限',width:150, sort: true},
		    {field: 'vGwZz',title: '岗位说明',width:260, sort: true},
		    {field: 'pageTemplate',title: '首页模板',width:150, sort: true},
		    //{field: 'remindDaysForContract',title: '劳动合同续签提前提醒天数',align: 'center',width:220, sort: true},
		    {field: 'roleOrder',title: '排序值',align: 'right',width:100, sort: true},
		    {field: 'deletedtext',title: '状态',align: 'center',width:80, sort: true},
		    {field: 'guid',title: 'guid',hide:true},	
		    {title: '操作',align: 'center',width:500,templet:'#barDh',fixed:'right'}
		]
		]
		,toolbar: '#toolbar'
		,height:'full-' + ( $('.north').height()+36),
	});
	//头工具栏事件
    table.on('toolbar(ftable)', function(obj){
        switch(obj.event){
            case 'addbtn':
            	layui.form.render();
            	$.modal.openHtml('新增角色','450','440','form_d','/system/role/addpost','post_form',function(result){
            		allReload(result);
                },'roleInfoItems',false);
                break;
        };
    });
	//监听工具条
    table.on('tool(ftable)', function (obj) {
        var data = obj.data;
        switch(obj.event){
        	case 'del':
        		$.operate.remove('确定要删除么？','/system/role/deletepost',{'roleInfoItems':JSON.stringify([{'guid':data.guid}])},function(result){
                    allReload(result)
                });
        		break;
        	case 'edit':
        		$("#guid1").val(data.guid);
            	$("#roleName1").val(data.roleName);
            	$("#vGwZz1").val(data.vGwZz);
            	//权限赋值
            	$.each(dataLimit,function(i,v){
            		if(data.roleDataLimit == v){
                    	$("#roleDataLimit1").val(i);
            		}
            	})
            	//模板赋值
            	$.each(pageTemplate,function(i,v){
            		if(data.pageTemplate == v){
                    	$("#pageTemplate").val(v);
            		}
            	})
            	if(data.deletedtext == "禁用"){
            		$("#deleted1").val(1);
            		$("#deletedtext1").prop("checked", false);
           		}
            	$("#remindDaysForContract1").val(data.remindDaysForContract);
            	$("#roleOrder1").val(data.roleOrder);
            	form.render();
            	$.modal.openHtml('编辑角色','450','440','form_d','/system/role/editpost','post_form',function(result){
            		allReload(result);
                },'roleInfoItems',false);
        		break;
        	case 'dataSet':
        		$.modal.openFull('分配数据权限 -【'+data.roleName+'】','/system/role/userandrolejurisdictionfordata?guid='+data.guid, function(index){
           		 var res = window["layui-layer-iframe" + index].callbackdata();
           		 	$.operate.post('/system/userandrolejurisdiction/fordataeditpost',{'infoItems':JSON.stringify(res),'upType':'formodule'},function(result){
                		/* setTimeout(function(){
                            window.location.reload();
                        }, 1000); */
                	});
           	 	})
        		break;
        	case 'funSet':
        		$.modal.openFull('分配功能权限 -【'+data.roleName+'】','/system/role/userandrolejurisdictionformodule?guid='+data.guid, function(index){
           			var res = window["layui-layer-iframe" + index].callbackdata();
           			$.operate.post('/system/userandrolejurisdiction/formoduleeditpost',{'infoItems':JSON.stringify(res),'upType':'formodule'},function(result){
            		/* setTimeout(function(){
                        window.location.reload();
                    }, 1000); */
            		});
        	 	})
        		break;
        	case 'fieldSet':
        		var mUrl = '/system/userandrolefieldstandard/userandrolefieldstandard?moduleName=ALL&moduleTable=ALL&vtype=role&fieldHidden=1&pid='+data.guid;
    		    $.modal.open('分配字段权限 -【'+data.roleName+'】' , mUrl, 600, 500, function(index){
    		        var res = window["layui-layer-iframe" + index].callbackdata();
    		        var pd = [];
    		        $.each(res,function(i,v){pd.push({fieldStandardId: v.value,fieldStandardName: v.title})})
    		        $.operate.post('/system/userandrolefieldstandard/savepost',{
   		        			'moduleName': 'ALL',
   		        			'moduleTable': 'ALL',
   		        			'pid': data.guid,
   		        			'vtype': 'role',
   		        			'fieldHidden': '1',
  		        			'infoItems':JSON.stringify(pd)
        			},function(result){
    		        	if(result.code == 0)layer.close(index);
    		        });
    		    });
        		break;
        }
    });
  	//监听排序事件 
    table.on('sort(ftable)', function(obj){
    	$.tablelist.sort('dhtable',obj);
    });
    form.on('switch(fdeleted)', function(data){
		if(data.elem.checked){
			$("#deleted1").val(0);
		}else{
			$("#deleted1").val(1);
		}
	})
	//搜索按钮
 	$('#btn-search').on('click', function () {
 		$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
        table.reload('dhtable', {page: {curr: 1},where:wherestr});
     });
 	//监听下拉框——添加条件
 	form.on('select(fft)', function(obj){
 		addMore(this);
 	});
   	//重新加载
     function allReload(result){
         if(result.code==0){
             setTimeout(function(){
                 layer.closeAll();
                 table.reload('dhtable', {url: "/system/role/list",page:{curr: 1}});
             }, 1000);
         }
     }
})
</script>
</body>
</html>